package com.ycu.jk16.mall.dao;

import static com.ycu.jk16.mall.util.common.AndroidMalConstant.USERTABLE;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.ycu.jk16.mall.dao.provider.UserDynaSqlProvider;
import com.ycu.jk16.mall.domain.User;

/**
 * 
 * @ClassName UserDao
 * @Description TODO(User表的查询接口)
 * @author 倪宗龙
 * @date 2018年12月8日 下午5:05:03
 * @version V1.0
 */
public interface UserDao {
	// 根据用户名和密码查找用户
	@Select("select * from " + USERTABLE + " where username = #{username} and password = #{password}")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
		@Result(column = "id", property = "id", id = true),
		@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
		@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
		@Result(column = "headportrait_url", property = "headPortraitUrl") })
	User selectByUserNameAndPwd(@Param("username") String username, @Param("password") String password);

	// 根据用户id查找用户
	@Select("select * from " + USERTABLE + " where id = #{id}")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
		@Result(column = "id", property = "id", id = true),
		@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
		@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
		@Result(column = "headportrait_url", property = "headPortraitUrl") })
	User selectById(@Param("id") Integer id);

	// 动态获取用户集合列表
	@SelectProvider(type = UserDynaSqlProvider.class, method = "selectWhitParam")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
		@Result(column = "id", property = "id", id = true),
		@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
		@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
		@Result(column = "headportrait_url", property = "headPortraitUrl") })
	List<User> selectUserWithParam(Map<String, Object> params);

	// 以用户名查找用户
	@Select("select * from " + USERTABLE + " where username = #{username}")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
		@Result(column = "id", property = "id", id = true),
		@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
		@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
		@Result(column = "headportrait_url", property = "headPortraitUrl") })
	User selectUserByUsername(@Param("username") String username);

	// 以邮箱查找用户
	@Select("select * from " + USERTABLE + " where email = #{email}")
	@Results({ // 将JavaBean里的变量名与数据库字段名不相符的进行标注
		@Result(column = "id", property = "id", id = true),
		@Result(column = "create_time", property = "createTime", javaType = java.util.Date.class),
		@Result(column = "update_time", property = "updateTime", javaType = java.util.Date.class),
		@Result(column = "headportrait_url", property = "headPortraitUrl") })
	User selectUserByEmail(@Param("email") String email);

	// 动态修改用户信息
	@SelectProvider(type = UserDynaSqlProvider.class, method = "updateUser")
	void updateUser(User user);

	// 根据参数查询用户总数
	@Select("select count(*) from " + USERTABLE)
	Integer countUser();
	// Integer countUser(Map<String, Object> params); 这里可以改成动态查询

	// 动态插入用户
	@SelectProvider(type = UserDynaSqlProvider.class, method = "insertUser")
	void insertUser(User user);
}
